// 新建 Data Access Points
const addNewDataAccessPoints = async () => {
  try {
    if (!Array.isArray(selectDataElement.value)) selectDataElement.value = [];
    const sendPointList = selectDataElement.value
      .map((selected) => {
        // 在 DataSendPoints 中查找与选中值匹配的数据
        const matchingPort = store.dataElementList.DataSendPoints.find((data) =>
          data.dataElements.some((element) => element.DataElement === selected)
        );
        if (matchingPort) {
          // 查找 dataElement 的详细信息
          const matchedElement = matchingPort.dataElements.find(
            (element) => element.DataElement === selected
          );
          if (matchedElement) {
            return {
              portName: matchingPort.rPort,
              portRef: matchingPort.fullPath,
              operationList: [
                {
                  operationName: matchedElement.DataElement,
                  operationRef: matchedElement.dataElementFullPath,
                },
              ],
            };
          }
        }
        return null;
      })
      .filter(Boolean);
    // 构建 receivePointList
    const receivePointList = selectDataElement.value
      .map((selected) => {
        const matchingPort =
          store.dataElementList.DataReceivePointByArguments.find((data) =>
            data.dataElements.some(
              (element) => element.DataElement === selected
            )
          );
        if (matchingPort) {
          // 查找 dataElement 的详细信息
          const matchedElement = matchingPort.dataElements.find(
            (element) => element.DataElement === selected
          );
          if (matchedElement) {
            return {
              portName: matchingPort.rPort,
              portRef: matchingPort.fullPath,
              operationList: [
                {
                  operationName: matchedElement.DataElement,
                  operationRef: matchedElement.dataElementFullPath,
                },
              ],
            };
          }
        }
        return null;
      })
      .filter(Boolean);

    const requestData = {
      packagePath: props.runnableFullPath,
      receivePointList: receivePointList.length ? receivePointList : undefined,
      sendPointList: sendPointList.length ? sendPointList : undefined,
    };

    if (!requestData.receivePointList && !requestData.sendPointList) {
      message.warning("receivePointList 和 sendPointList 不能同时为空");
      return;
    }

    const response = await component.createNewDataAccessPoint(requestData);
    if (response.data.respData) {
      message.success(response.data.respMsg);
    } else {
      message.error(response.data.respMsg);
    }
  } catch (error) {
    message.error(error);
    selectDataElement.value = [];
  } finally {
    console.log(selectDataElement.value);

    selectDataElement.value = [];
    dataModalVisible.value = false;
    store.getDataList(
      props.runnableFullPath,
      dataAccessPoint.value,
      dataElement.value,
      accessingPort.value
    );

    store
    vuex

    pinia
  }
};
